﻿namespace HRM.Update.Internet
{
    using System;
    using System.Runtime.InteropServices;

    [Flags]
    internal enum ConnectionState
    {
        InternetConnectionModem = 1,
        InternetConnectionLan = 2,
        InternetConnectionProxy = 4,
        InternetRasInstalled = 16,
        InternetConnectionOffline = 32,
        InternetConnectionConfigured = 64
    }

    public class Internet
    {
        [DllImport("wininet.dll", CharSet=CharSet.Auto)]
        private static extern bool InternetGetConnectedState(ref ConnectionState lpdwFlags, int dwReserved);
        public static unsafe bool IsConnectedToInternet()
        {
            ConnectionState connectionState = (ConnectionState)0;
            try
            {
                return InternetGetConnectedState(ref connectionState, 0);
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}

